# Contributor: Fabricio Silva <hi@fabricio.dev>
# Maintainer: Fabricio Silva <hi@fabricio.dev>
pkgname=autobrr
pkgver=1.48.0
pkgrel=0
pkgdesc="The modern download automation tool for torrents"
url="https://autobrr.com/"
arch="all"
license="GPL-2.0-or-later"
options="net" # net for go
makedepends="go"
subpackages="$pkgname-openrc"
install="$pkgname.pre-install"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/autobrr/autobrr/archive/v$pkgver.tar.gz
	$pkgname-web-dist-$pkgver.tar.gz::https://github.com/autobrr/autobrr/releases/download/v$pkgver/web-dist.tar.gz
	autobrr.initd
	autobrr.confd
	"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

prepare() {
	default_prepare

	# frontend pre-built files (symlink dont work)
	rm -rf web/dist
	cp -al "$srcdir"/web/dist web/dist

	go mod download
}

build() {
	local ldflags="
		-X main.version=v$pkgver
		-X main.commit=alpine-r$pkgrel
		-X main.date=$(date -u "+%Y-%m-%dT%H:%M:%SZ" ${SOURCE_DATE_EPOCH:+-d @$SOURCE_DATE_EPOCH})
	"

	mkdir -p bin
	go build -ldflags "$ldflags" -o bin/ ./cmd/...
}

check() {
	go test ./...
}

package() {
	install -Dm755 ./bin/* -t "$pkgdir"/usr/bin

	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -Dm644 "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
}

sha512sums="
b495325df144378524d34b108499eb377a3e5abf061767953f3a19ca5f73524b97bb9f73756ebaccd57ab5692aa218f83fe1d7aeaa06a26772c1a382da631fca  autobrr-1.48.0.tar.gz
5acf5e3e4c420816f8478b88f371e9eb1d24076d7a6e40f96c9cf876189ab846a041f91058c94c53f19970b1d35f34dfeb61364a6b76d807e16aca2cedf4cee2  autobrr-web-dist-1.48.0.tar.gz
42ce693eca67ca8b4c863440ebfb3efb41c197302274ccecd1b080c3e1f01e03078ab46b2fae8ca6cf5add4153296adb10e324b02dbe89c939465305be49f760  autobrr.initd
4072cabb7131a23283b1fecdd1370eb935ae156284972a5e503de36054a358f74112a40e200662386e85af51507213e3f25afdf343a2673e6ef372b7b5e04a80  autobrr.confd
"
